#!/usr/bin/bash
if [ "$1" = "" ];then
	echo "缺少输入文件"
	exit 1
fi
echo "生成分立音频wav文件"
mkdir -p tmp
cat $1 | while read line;do
	fn=$(echo $line | cut -f1 -d'-')
	t=$(echo $fn | egrep '^[0-9]+[:：][0-9]+$')
	if [ "$t" = "" ];then
		continue
	fi
	length=${#fn}
	offset=$(expr $length + 1)
	txt=${line:$offset}
	echo $fn
	echo $txt
	echo $txt | xfttsgo -o tmp/${fn}.wav -stdin
done

echo "合并WAV文件"
merge-timed-wav tmp
ffmpeg -y -i out.wav out.mp3
rm out.wav
rm -rf tmp
